﻿using System;
using System.Windows.Media;
using DeepEarth.Client.MapControl.Layers;

namespace DeepEarth.Client.Services.MapsForFree
{
    public enum MapForFreeMapModes
    {
        Relief,
        Country
    }

    public class MapForFreeTileSource : TileSource
    {
        // Fields
        private bool _IsInitialized;
        private MapForFreeMapModes _MapMode;
        private EventHandler InitializeCompleted;
        //   private const string TilePath = "http://maps-for-free.com/layer/relief/z3/row1/3_5-1.jpg";
        private const string TilePath = "http://maps-for-free.com/layer/relief/z{Z}/row{Y}/{Z}_{X}-{Y}.jpg";

        // Methods
        public MapForFreeTileSource()
        {
        }

        public MapForFreeTileSource(MapForFreeMapModes mode)
        {
            this.MapMode = mode;
        }

        public override Uri GetTile(int tileLevel, int tilePositionX, int tilePositionY)
        {
            if (this.IsInitialized)
            {
                int num = this.TileToZoom(tileLevel);
                return new Uri(TilePath.Replace("{Z}", num.ToString()).Replace("{X}", tilePositionX.ToString()).Replace("{Y}", tilePositionY.ToString()));
            }
            return null;
        }

        // Properties
        public override bool IsInitialized
        {
            get
            {
                return this._IsInitialized;
            }
        }

        public MapForFreeMapModes MapMode
        {
            get
            {
                return this._MapMode;
            }
            set
            {
                this._MapMode = value;
                base.Id = value.ToString();
                this._IsInitialized = true;
                if (this.InitializeCompleted != null)
                {
                    this.InitializeCompleted(this, null);
                }
            }
        }

        public override Color TileColor
        {
            get
            {
                return Color.FromArgb(0xff, 0xb9, 0xd1, 0xd1);
            }
        }
    }


}
